package com.tz.colawallet.ui.presenter;

import com.tz.colawallet.basecode.base.BaseBiz;
import com.tz.colawallet.basecode.base.BaseRespNew;
import com.tz.colawallet.bean.GetTags;
import com.tz.colawallet.bean.Recommand;
import com.tz.colawallet.ui.biz.MainSecondFragBiz;
import com.tz.colawallet.ui.contract.MainSecondFragContract;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by Administrator on 2017/10/25.
 */

public class MainSecondFragPresenter implements MainSecondFragContract.MainSecondFragPresenter {

    MainSecondFragContract.View view;
    MainSecondFragBiz biz;

    @Inject
    public MainSecondFragPresenter(MainSecondFragContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        this.biz = (MainSecondFragBiz) biz;
    }

    @Override
    public void recommand(Integer loanMoneyId, Integer loanTypeId, Integer page, Integer size) {
        view.loading(true);
        biz.recommand(view.curContext(), loanMoneyId, loanTypeId, page, size, new BaseBiz.Callback<BaseRespNew<List<Recommand>>>() {
            @Override
            public void onSuccess(BaseRespNew<List<Recommand>> o) {
                view.showRecommand(o.getData());
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }

    @Override
    public void checkDetail() {
        view.loading(true);
        biz.checkDetail(view.curContext(), new BaseBiz.Callback<BaseRespNew>() {
            @Override
            public void onSuccess(BaseRespNew o) {
                view.showCheckDetail(o.getData());
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }


    @Override
    public void getLoanMoney() {
        view.loading(true);
        biz.getLoanMoney(view.curContext(), new BaseBiz.Callback<BaseRespNew<List<GetTags>>>() {
            @Override
            public void onSuccess(BaseRespNew<List<GetTags>> o) {
                view.showGetLoanMoney(o.getData());
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }

    @Override
    public void getLoanType() {
        view.loading(true);
        biz.getLoanType(view.curContext(), new BaseBiz.Callback<BaseRespNew<List<GetTags>>>() {
            @Override
            public void onSuccess(BaseRespNew<List<GetTags>> o) {
                view.showGetLoanType(o.getData());
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }


    @Override
    public void addApplyNum(Integer id) {
        view.loading(true);
        biz.addApplyNum(view.curContext(), id, new BaseBiz.Callback<BaseRespNew>() {
            @Override
            public void onSuccess(BaseRespNew o) {
//                view.showCheckDetail(o.getData());
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }
}
